<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>

<body>

</body>

<!--区别[]和{}的三种方法------------------------------------------------------------------------------------------------>
<script type="text/html">
    //
    var a = [];
    var b = {};
    //1. some instanceof Array
    console.log(a instanceof Array);
    console.log(b instanceof Array);
    //2. Object.prototype.toString.call(some);
    console.log(Object.prototype.toString.call(a));
    console.log(Object.prototype.toString.call(b));
    //3. constructor
    console.log(a.constructor);
    console.log(b.constructor);
    //拓展：查看变量类型
    console.log(Object.prototype.toString.call(1));
    console.log(Object.prototype.toString.call('str'));
    console.log(Object.prototype.toString.call(true));
    console.log(Object.prototype.toString.call(null));
    console.log(Object.prototype.toString.call(undefined));
    console.log(Object.prototype.toString.call({}));
    console.log(Object.prototype.toString.call([]));
    console.log(Object.prototype.toString.call(Object));
    //其实质
    console.log([].__proto__ === Array.prototype);
    console.log([].__proto__.__proto__ === Object.prototype);
</script>

<!--Function是所有函数的构造函数----------------------------------------------------------------------------------------->
<script type="text/html">
    //
    console.log('----------');
    console.log(Function instanceof Object);        //true
    console.log(Function instanceof Function);      //true
    console.log(Object instanceof Function);        //true
    console.log(Object instanceof Object);          //true
</script>

<!--arguments---------------------------------------------------------------------------------------------------------->
<script type="text/html">
    //
    //arguments.collee指向其所在函数名，用此方法可以实现无名（立即执行）函数的递归
    let num = (function (n) {
    if (n === 1)
    return 1;
    else
    return n * arguments.callee(n - 1);
    })(20);
    console.log(num);
</script>

<!--for-in循环注意事项-------------------------------------------------------------------------------------------------->
<script type="text/html">
    //
    let obj = {
    a: 1,
    b: 2,
    c: 3,
    prop: 'prop'
    };
    for (let prop in obj) {
    console.log(obj.prop);
    }
    for (let prop in obj) {
    console.log(obj[prop]);
    }
</script>

<!--深拷贝------------------------------------------------------------------------------------------------------------->
<script>
  // type="text/html"
  function deepCopy(obj) {
    if (!obj) return;
    // hash表，记录所有的对象的引用关系
    let map = new WeakMap();
    function dp(obj) {
      let result = null;
      let keys = Object.keys(obj);
      let key = null,
        temp = null,
        existobj = null;
      existobj = map.get(obj);
      //如果这个对象已经被记录则直接返回
      if (existobj) {
        return existobj;
      }
      result = {}
      map.set(obj, result);
      for (let i = 0, len = keys.length; i < len; i++) {
        key = keys[i];
        temp = obj[key];
        if (temp && typeof temp === 'object') {
          result[key] = dp(temp);
        } else {
          result[key] = temp;
        }
      }
      return result;
    }
    return dp(obj);
  }
  let a = { some: null };
  console.log(deepCopy());
</script>

</html>